package leetcode.year2021.month10;

import java.util.List;

public class _01_01ReverseList206 {

  public ListNode reverseList(ListNode head) {
    if (head == null || head.next == null){
      return head;
    }

    ListNode next = head.next;
    head.next = null;

    while (next != null) {
      ListNode tempNext = next.next;
      next.next = head;
      head = next;
      next = tempNext;
    }

    return head;
  }

  /**
   * 给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
   */

  public class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
      this.val = val;
    }

    ListNode(int val, ListNode next) {
      this.val = val;
      this.next = next;
    }
  }

}
